package com.itbour.web.action.trade;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.trade.BuyTmplInfoDto;
import com.itbour.service.trade.BuyTmplService;
import com.opensymphony.xwork2.ActionContext;


/**
 * copyright Itbour team 2017
 * 
 * @author xc
 */

public class GetBuyTmplWebAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private BuyTmplService buyTmplService;
	
	private HashMap<String, Object> buyMapResult = new HashMap<String, Object>();//[分页]订单信息列表
	private List<BuyTmplInfoDto> buyInfoList;// 订单信息列表

	private String findTmplId;// 检索条件[模版ID]
	private String findUserId;// 检索条件[用户ID]
	private String findType;// 检索条件[模版分类]
	private String findState;// 检索条件[订单状态]
	private String findPayPf;// 检索条件[支付平台]
	private String findDateStart;// 检索条件[时间范围(起始)]
	private String findDateEnd;// 检索条件[时间范围(截止)]
	private String ids;// 通用ids[逗号连接]
	
	
	
	// 分页获取订单信息
	public String getBuyTmplInfoPg() throws Exception {
		// 用户信息
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNumber = request.getParameter("page");
		String pageSize = request.getParameter("rows");
		
		Map<String, Object> param = new HashMap<String, Object>();
		if (StringUtils.isNotEmpty(findTmplId)) {
			param.put("tmpl_id", findTmplId);
		}
		if (StringUtils.isNotEmpty(findUserId)) {
			param.put("user_id", findUserId);
		}
		if (StringUtils.isNotEmpty(findType)) {
			param.put("type", findType);
		}
		if (StringUtils.isNotEmpty(findState)) {
			param.put("state", findState);
		}
		if (StringUtils.isNotEmpty(findPayPf)) {
			param.put("pay_platform", findPayPf);
		}
		if (StringUtils.isNotBlank(findDateStart)) {
			param.put("valid_time_start", findDateStart);
		}
		if (StringUtils.isNotBlank(findDateEnd)) {
			param.put("valid_time_end", findDateEnd);
		}
		Page page = buyTmplService.buyPgQuery(param,
				Integer.parseInt(pageNumber),
				Integer.parseInt(pageSize));
		HashMap<String, Object> resMap = new HashMap<String, Object>();
		resMap.put("total", page.getTotalCount());
		resMap.put("rows", page.getResult());
		//writeJSON(resMap);
		buyMapResult = resMap;
		return SUCCESS;
	}
	
	// 获取订单信息列表
	public String getBuyTmplInfoLst() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		Map<String, Object> param = new HashMap<String, Object>();
		String id = request.getParameter("buy_id");
		if (StringUtils.isNotEmpty(id)) {
			param.put("buy_id", id);
		}
		buyInfoList = buyTmplService.selectBuyInfo(param);
		return SUCCESS;
	}

	public BuyTmplService getBuyTmplService() {
		return buyTmplService;
	}

	public void setBuyTmplService(BuyTmplService buyTmplService) {
		this.buyTmplService = buyTmplService;
	}

	public HashMap<String, Object> getBuyMapResult() {
		return buyMapResult;
	}

	public void setBuyMapResult(HashMap<String, Object> buyMapResult) {
		this.buyMapResult = buyMapResult;
	}

	public List<BuyTmplInfoDto> getBuyInfoList() {
		return buyInfoList;
	}

	public void setBuyInfoList(List<BuyTmplInfoDto> buyInfoList) {
		this.buyInfoList = buyInfoList;
	}

	public String getFindTmplId() {
		return findTmplId;
	}

	public void setFindTmplId(String findTmplId) {
		this.findTmplId = findTmplId;
	}

	public String getFindUserId() {
		return findUserId;
	}

	public void setFindUserId(String findUserId) {
		this.findUserId = findUserId;
	}

	public String getFindType() {
		return findType;
	}

	public void setFindType(String findType) {
		this.findType = findType;
	}

	public String getFindState() {
		return findState;
	}

	public void setFindState(String findState) {
		this.findState = findState;
	}

	public String getFindPayPf() {
		return findPayPf;
	}

	public void setFindPayPf(String findPayPf) {
		this.findPayPf = findPayPf;
	}

	public String getFindDateStart() {
		return findDateStart;
	}

	public void setFindDateStart(String findDateStart) {
		this.findDateStart = findDateStart;
	}

	public String getFindDateEnd() {
		return findDateEnd;
	}

	public void setFindDateEnd(String findDateEnd) {
		this.findDateEnd = findDateEnd;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}
	
}
